/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ControllerLag;
import ModelLag.*;
import DBLag.*;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Ronni
 */
public class CustomerCTR {
 
    private IFDbCustomer dbCustomer;

    public CustomerCTR() {
        dbCustomer = new DbCustomer();
    }

    
    public Customer findCustomer(String phoneNo) {
        return dbCustomer.findCustomer(phoneNo);
    }

    
    public ArrayList<Customer> searchCustomer(String searchString) {
        return dbCustomer.searchCustomer(searchString);
    }

    
    public ArrayList<Customer> getAllCustomers() {
        return dbCustomer.getAllCustomers();
    }
    public int createCustomer(String phoneNo, String fName, String lName, String address, String zipCode, String email) throws SQLException
    {
        Customer newCustomer = new Customer(phoneNo,fName,lName,address,zipCode,email);
        return insertCustomer(newCustomer);
    }
    
    public int insertCustomer(Customer newCustomer) throws SQLException {
        int rc;
        try{
        rc = dbCustomer.insertCustomer(newCustomer);
        }catch(SQLException e)
        {
            throw new SQLException(e);
        }
        return rc;
    }

    
    public int updateCustomer(String phoneNo, String fName, String lName, String address, String zipCode, String email) throws SQLException {
        Customer newCustomer = new Customer(phoneNo,fName,lName,address,zipCode,email);
        int rc;
        try{
            rc = dbCustomer.updateCustomer(newCustomer);
        }catch(SQLException e)
        {
            throw new SQLException(e);
        }
        return rc;
    
    }

    
    public int deleteCustomer(String phoneNo) throws SQLException{
        Customer newCustomer = new Customer();
        newCustomer.setPhoneNo(phoneNo);
        int rc;
        try{
            rc = dbCustomer.deleteCustomer(newCustomer);
        }catch(SQLException e)
        {
            throw new SQLException(e);
        }
        return rc;
    }

    
    
    
    
}
